﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />    
    <title>简睿捷智能制造PDM系统登录</title>
    <link href="Content/bootstrap.min.css" rel="stylesheet" />
    <link href="css/login.css" rel="stylesheet" />

</head>
<body>
    <nav class="nav navbar-fixed-top navbarTop">
        <div style="margin-top:10px;" id="head_title">
            <img class="img-responsive" src="images/logo.png" style="height: 30px;float:left" />
            <span>简睿捷智能制造产品数据管理系统</span>
        </div>
    </nav>
    <div id="introduction">
        <div id="introduction-head">
            <p>欢迎来到简睿捷PDM系统</p>
        </div>
        <div id="introduction-detail">
            <p>
                专注企业产品数据管理二十年
            </p>
            <p>
                感谢有您，一路陪伴
            </p>
            <p>
                您的支持，是我们前进的最大动力
            </p>
        </div>
    </div>
    <form id="login">
        <div class="title_bg">
            <div class="title">
                <p>登陆简睿捷PDM</p>
            </div>
        </div>
        <fieldset id="inputs">
            <input id="username" name="login_username" type="text" placeholder="Username" autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus autofocus=autofocus required=required />
            <input id="password" name="login_password" type="password" placeholder="Password" required=required />
        </fieldset>
        <fieldset id="actions">
            <input type="checkbox" id="saveusr" /><label>Remember me</label>
            <input type="button" id="loginBtn" onclick="login()" value="登   陆" />
        </fieldset>
    </form>

    <script>
        window.onload = function (e) {
            loadcookie();
        }
        function login() {
            var username = document.getElementById("username").value;
            var password = document.getElementById("password").value;
            if (username == "") {
                alert("请输入用户名");
                return;
            }


            var saveusr = document.getElementById("saveusr").checked;
            if (saveusr) {
                setCookie("username", username, 365);
                setCookie("password", password, 365);
            }
            var data = $('#login').serialize();


            $.ajax({
                cache: true,
                type: "POST",
                url: '../api2/login',
                data: data,
                async: false,
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert('status:' + XMLHttpRequest.status);
                },
                success: function (data) {
                    var url = getQueryString("redirect");
                    //获取屏幕宽度，选择跳转界面
                    //PC端：直接跳转文档发放系统pdm.html  手机端：跳转到index.html
                    var qwid = screen.width;
                    if (url == null || url.length == 0) {
                        if (qwid <= 415) {
                            url = "index.html";
                        } else {
                            url = "pdm.html";
                        }
                    }
                    if (data.resFlag != 0)
                        alert(data.errMsg);
                    else {
                        window.location.href = url;
                    }
                }
            });
        }

        function loadcookie() {
            var username = getCookie("username");
            document.getElementById("username").value = username;
            var pwd = getCookie("password");
            document.getElementById("password").value = pwd;
        }
        function getCookie(c_name) {
            if (document.cookie.length > 0) {
                c_start = document.cookie.indexOf(c_name + "=")
                if (c_start != -1) {
                    c_start = c_start + c_name.length + 1
                    c_end = document.cookie.indexOf(";", c_start)
                    if (c_end == -1) c_end = document.cookie.length
                    return unescape(document.cookie.substring(c_start, c_end))
                }
            }
            return ""
        }

        function setCookie(c_name, value, expiredays) {
            var exdate = new Date()
            exdate.setDate(exdate.getDate() + expiredays)
            document.cookie = c_name + "=" + escape(value) +
            ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
        }

        function keyLogin() {
            if (event.keyCode == 13)   //回车键的键值为13
                document.getElementById("loginBtn").click();  //调用登录按钮的登录事件
        }

    </script>

    <script src="../Scripts/jridgecommon.js"></script>
    <script src="Scripts/jquery-1.10.2.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>
</body>
</html>
